<template>
  <div class="login">
    <div class="con">
      <h3 class="text-center">登录</h3>
      <el-input v-model="islogin.username" placeholder="请输入用户名" clearable></el-input>
      <el-input v-model="islogin.password" placeholder="请输入密码" clearable show-password></el-input>
      <div class="text-center">
        <el-button type="primary" @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>

import { mapGetters, mapActions } from "vuex";
import { requserlogin } from '../../http/api';
import { successAlert } from '../../utils/alert'
export default {
  data(){
    return {
      islogin:{
        username:'',
        password:'',
      }
      
    }
  },
  methods: {
    ...mapActions({
      changeUser:"changeUser"
    }),
    // 3.点了登录按钮 
    login(){
      requserlogin(this.islogin).then(res=>{
        if(res.data.code==200){
          //弹成功
          successAlert(res.data.msg);
          //4.用户信息存起来 ---vuex和本地存储都存
          // res.data.list  
          this.changeUser(res.data.list)
          //跳转页面
          this.$router.push("/")
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
@import "../../less/index.less";
.login {
  width: 100vw;
  height: 100vh;
  position: relative;
  background: linear-gradient(to right, @bg-light, @bg-deep);
  .con {
    width: 300px;
    background: #fff;
    padding: @padding20;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    border-radius: @padding10;
    h3,.el-input{
        margin-bottom: @padding10;
    }
  }
}
</style>